const Router = require("koa-router");
const UserController = require("../controller/UserContoller");
const router = new Router({ prefix: "/users" });

// 注册
router.post("/signup", UserController.signup);

// 登录
router.post("/signin", UserController.signin);

// 发送验证码
// username, email
router.post("/verify", UserController.verify);

router.get("/index", async ctx => {
  console.log(ctx.state.user);
  console.log(ctx.session);
  if (!ctx.isAuthenticated()) {
    return (ctx.body = {
      code: -1,
      msg: "未通过验证"
    });
  }
  return (ctx.body = {
    code: 0,
    msg: "恭喜，通过验证"
  });
});

module.exports = router;
